package com.gcxy.conf.exception.handler;

import com.gcxy.conf.exception.annotation.GlobalException;
import com.gcxy.conf.exception.exception.IGlobalException;
import com.gcxy.conf.result.R;
import com.gcxy.conf.result.ResultCodeEnum;
import com.fasterxml.jackson.core.JsonParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * JSON解析异常
 * JsonParseException：对json进行解析时产生的问题，通常表示为解析内容不符合JSON语法
 *
 * @author shineTan
 * @date 2022/12/26 14:26
 */
@GlobalException(throwable = JsonParseException.class)
public class JsonParseExceptionHandler implements IGlobalException<R, JsonParseException> {

    @Override
    public R exception(JsonParseException throwable, HttpServletRequest request, HttpServletResponse response) {
        return R.Failed(ResultCodeEnum.REQUEST_PARAM_ERROR.getCode(), String.format("请求参数JSON格式错误"));
    }
}
